package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.common.persistence.model.User;
import com.stylefeng.guns.modular.system.dao.UserMgrDao;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用swagger 测试接口文档
 * @author roderick kennedy roderick_kennedy@outlook.com
 * @date 2017年9月11日17:36:00
 */
@Api(value = "Test", description = "Test the swagger API")
@RestController
@RequestMapping("/Test")
public class TestController {

    @Autowired
    private UserMgrDao userMapper;

    @ApiOperation(value = "get user by account", notes = "Get get user by account", response = User.class)
    @ApiResponses(value = {@ApiResponse(code = 405, message = "Invalid input", response = User.class) })
    @RequestMapping(value = "/user", method = RequestMethod.POST)
    public ResponseEntity<User>  getUser(
            @ApiParam(value = "The account of the user" , required=true ) @RequestParam String account){
        User user = userMapper.getByAccount(account);
        if (user != null){
            return new ResponseEntity<>(user, HttpStatus.OK);
        }
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
